<?php use_stylesheet('orders.css') //load css pf order page   ?>
<?php use_stylesheet('hoverTables.css') //load css of tables  ?>
<div id="par_header"><!-- the top area with buttons and search -->
    <div id="bt_area"><!-- the top area with buttons -->
        <div class="button"><!-- add new order button -->
            <a href="<?php echo url_for('sales_new_order') ?>">
                <img src="<?php echo image_path('Buttons/bt_add_order.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_add_order_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_add_order.png') ?>';" title="Add new customer order"/>
            </a>
        </div>
        <div class="button"><!-- add new return button -->
            <a href="<?php echo url_for('sales_return_order') ?>">
                <img src="<?php echo image_path('Buttons/bt_return.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_return_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_return.png') ?>';" title="Add new return order"/>
            </a>
        </div>
        <div class="button"><!-- add new stock order button -->
            <a href="<?php echo url_for('sales_stock_order') ?>">
                <img src="<?php echo image_path('Buttons/bt_stock_order.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_stock_order_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_stock_order.png') ?>';" title="Add new stock order"/>
            </a>
        </div>
    </div><!-- close button area -->
    <div id="search"><!-- search for orders -->
        <?php echo form_tag('sales_filter_orders') ?>
        <fieldset>
            <legend class="bold">Search Order</legend>
            <table>    
                <tr>
                    <td>Order No.</td>
                    <td class="input_small"><?php echo $filter['id']->render() ?></td><!-- renders input field for id, small width for input -->
                </tr>
                <tr>
                    <td>Category</td>
                    <td><?php echo $filter['category_name']->render() ?></td><!-- renders input field for category -->
                </tr>
                <?php echo $filter['status']->renderRow() ?><!-- renders the status in a dropdown -->
                <tr>
                    <td>
                        <input type="submit" value="" name="submit_filter" class="bt_search" title="Search order"/><!-- the search submit button, when having mouse on it, it shows the text 'Search order' -->
                    </td>
                </tr>
            </table>
            <div id="del_list"><!-- refresh the contact list, back to full list -->
                <a href="<?php echo url_for('sales_index_orders') ?>">
                    <img src="<?php echo image_path('Buttons/bt_cancel_small.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_cancel_small_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_cancel_small.png') ?>';" width="55px" title="Back to complete order list"/><!-- when having mouse on it, it shows the text 'Back to complete order list' -->
                </a>
            </div>
            <span id="tooltip2"><a href=""><img src="<?php echo image_path('Buttons/bt_help.png') ?>" /><span>Fill in one or more field(s) to search an order</span></a></span>
        </fieldset>
        <!--</form>-->     
    </div><!-- close search -->
</div><!-- close par header -->
<h2>Orders</h2>
<div id="orders" class="table_div"><!-- table with all orders -->
    <table>
        <tr class="bold head">
            <td>Order No.</td>
            <td>Contact</td>
            <td>Category</td>
            <td>Date In</td>
            <td>Date Out</td>
            <td>Date Due</td>
            <td>Status</td>
            <td width="35px"></td>
            <td width="35px"></td>
        </tr>
        <!-- You can click on a table row to see all the information of that order -->
        <?php foreach ($orders as $i=>$order): ?>
        <?php $contact = ContactTable::getInstance()->find($order->getContactId()) ?>
            <tr class="table_hov <?php echo fmod($i, 2) ? 'even' : 'odd' ?>">
                <td><a href="<?php echo url_for('sales_show_order', $order) ?>"><?php echo $order->getId() ?></a></td>
                <td><a href="<?php echo url_for('sales_show_order', $order) ?>"><?php echo $contact->getName() ?></a></td>
                <td><a href="<?php echo url_for('sales_show_order', $order) ?>"><?php echo $order->getCategoryName() ?></a></td>
                <td><a href="<?php echo url_for('sales_show_order', $order) ?>"><?php echo $order->getDateRecieved() ?></a></td>
                <td><a href="<?php echo url_for('sales_show_order', $order) ?>"><?php echo $order->getDateCompleted() ?></a></td>
                <td><a href="<?php echo url_for('sales_show_order', $order) ?>"><?php echo $order->getDateDue() ?></a></td>
                <td><a href="<?php echo url_for('sales_show_order', $order) ?>"><?php echo $order->getStatus() ?></a></td>
                <td style="text-align: center;"><a href="<?php echo url_for('sales_print_order',$order) ?>"><img src="<?php echo image_path('Buttons/bt_print_small.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_print_small_hov.png') ?>';"  onmouseout="this.src='<?php echo image_path('Buttons/bt_print_small.png') ?>';" title="Print"/></a></td>
                <?php if($order->getCategoryName() == 'customer order' && $order->getStatus() != 'collected'){ ?>
                <td style="text-align: center;"><a href="<?php echo url_for('sales/editOrder?id='.$order->getId()) ?>"><img src="<?php echo image_path('Buttons/bt_edit_small.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_edit_small_hov.png') ?>';"  onmouseout="this.src='<?php echo image_path('Buttons/bt_edit_small.png') ?>';" title="Edit order"/></a></td>
                <?php } else if($order->getCategoryName() == 'stock order' && $order->getStatus() != 'ready'){ ?>
                <td style="text-align: center;"><a href="<?php echo url_for('sales/editStockOrder?id='.$order->getId()) ?>"><img src="<?php echo image_path('Buttons/bt_edit_small.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_edit_small_hov.png') ?>';"  onmouseout="this.src='<?php echo image_path('Buttons/bt_edit_small.png') ?>';" title="Edit stock order"/></a></td>    
                <?php } else { ?>
                <td></td>
                <?php } ?>
            </tr>
        <?php endforeach; ?>
    </table>
</div>
